home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
6
/
ctone.zip
/
TONE.C
< prev
next >
Wrap
Text File
|
1984-12-04
|
1KB
|
39 lines
/* FILENAME: tone.c
DESCRIPTION: generate a tone of given frequency and length
*/
#define TIMERMODE 182 /* code to put timer in right mode */
#define FREQSCALE 1190000L /* basic time frequency in hertz */
#define TIMESCALE 1230L /* number of counts in 0.1 second */
#define T_MODEPORT 67 /* port controls timer mode */
#define FREQPORT 66 /* port controls tone frequency */
#define BEEPPORT 97 /* port controls speaker */
#define ON 79 /* signal to turn speaker on */
tone (freq, time)
int freq, time;
{
int hibyte, lowbyte, port;
long i, count, divisor;
divisor = FREQSCALE / freq; /* scale freq to timer units */
lowbyte = divisor % 256; /* break integer into */
hibyte = divisor >> 8; /* two bytes */
count = TIMESCALE * time; /* convert time to timer units*/
outp (T_MODEPORT, TIMERMODE); /* prepare timer for input */
outp (FREQPORT, lowbyte); /* set low byte of timer reg */
outp (FREQPORT, hibyte); /* set high byte of timer reg */
port = inp (BEEPPORT); /* save port setting */
outp (BEEPPORT, ON); /* turn speaker on */
for (i = 0; i < count; i++)
; /* mark time */
outp (BEEPPORT, port); /* turn speaker off, restore */
/* original setting */
}